﻿
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Xml.Serialization
<Serializable()> Public Class AermodResultsPollute
    Private m_ResultGroups(-1) As ResultGroups
    '废弃的对象-----------------------
    Private m_PostResult As New PostResult
    '废弃的对象-----------------------
    Private m_Name As String = ""
    
    ''' <summary>
    ''' 计算结果中的数组类
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ResultGroups() As ResultGroups()
        Get
            Return Me.m_ResultGroups
        End Get
        Set(ByVal value As ResultGroups())
            Me.m_ResultGroups = value
        End Set
    End Property
    Property PostResult() As PostResult
        Get
            Return m_PostResult
        End Get
        Set(ByVal value As PostResult)
            m_PostResult = value
        End Set
    End Property

    Public Function GetData(ByVal strAERMODOUT As String(), ByVal Receptor As Receptor, ByVal IsDep As Boolean, ByVal AerageTime As AerageingTime, ByVal OutPutOption As OutPuts, ByVal Groups As Groups, ByVal IsAnalisis As Boolean, ByVal soruces As Source, ByVal strname As String, ByVal Control As Control, ByVal iIndexPollution As Integer, ByVal PostPath As String, ByVal version As String, ByVal SavePath As String) As Boolean
        ReDim m_ResultGroups(Groups.ArrayGroup.Length - 1)
        For i As Integer = 0 To Groups.ArrayGroup.Length - 1 '根据分组求
            m_ResultGroups(i) = New ResultGroups
            Dim strGroup As String = Groups.ArrayGroup(i).GroupID
            If Me.m_ResultGroups(i).GetData(strAERMODOUT, Receptor, IsDep, AerageTime, OutPutOption, strGroup, IsAnalisis, Groups.ArrayGroup(i).AllSlelectedCount(soruces, strname), version, Control, PostPath, Groups, i) = False Then '期间平均
                Return False
            End If
            '保存该组的数据
            Me.m_ResultGroups(i).SaveData(SavePath, Groups.ArrayGroup(i).Name & ".gdt")
        Next
        Return True
    End Function
    ''' <summary>
    ''' 计算结果对应的污染物名称
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Name() As String
        Get
            Return m_Name
        End Get
        Set(ByVal value As String)
            m_Name = value
        End Set
    End Property
    ''' <summary>
    ''' 读取并返回结果
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetResult(ByVal FileName As String) As AermodResultsPollute
        Try
            Dim fileStr As Stream = File.Open(FileName, FileMode.Open)

            ' Create a formatter object based on command line arguments
            Dim formatter As IFormatter

            formatter = CType(New BinaryFormatter, IFormatter)
            ' Deserialize the object graph from stream
            Dim sdis As New AermodResultsPollute
            sdis = CType(formatter.Deserialize(fileStr), AermodResultsPollute)
            fileStr.Close()
            Return sdis
        Catch ex As Exception
            MsgBox("保存文件错误!")
            Return Nothing
        End Try
    End Function

    ''' <summary>
    ''' 保存结果文件
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SaveResult(ByVal FileName As String)

        Try
            ' Create a filestream object
            Dim fileStr As Stream = File.Open(FileName, FileMode.Create)
            ' Create a linked list object and populate it with random nodes
            Dim sdis As New AermodResultsPollute
            sdis = Me
            ' Create a formatter object based on command line arguments
            Dim formatter As IFormatter
            formatter = CType(New BinaryFormatter, IFormatter)
            ' Serialize the object graph to stream
            formatter.Serialize(fileStr, sdis)
            ' All done
            fileStr.Close()
        Catch ex As Exception
            MsgBox("保存文件错误!")
        End Try
    End Sub
End Class
